package st.business.tepth.business.taskallocation.lag;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.List;

import butterknife.BindView;
import st.business.tepth.R;
import st.business.tepth.R2;
import st.business.tepth.base.OnItemChooseListener;
import st.business.tepth.business.bean.LagInfoBean;
import st.shadow.library.core.base.mvp.MvpFragment;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-06-10 14:31
 * 滞后处理
 */

public class LagDelegate extends MvpFragment<LagPresenter> implements LagContract.View {
    public static LagDelegate newInstance(int repairId) {
        Bundle bundle = new Bundle();
        bundle.putInt("repairId", repairId);
        LagDelegate delegate = new LagDelegate();
        delegate.setArguments(bundle);
        return delegate;
    }

    @BindView(R2.id.recycler_view_tab)
    RecyclerView mRecyclerView;
    private int mRepairId;
    private TabAdapter mClassificationAdapter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            mRepairId = bundle.getInt("repairId");
        }
    }

    @Override
    public LagPresenter getPresenter() {
        return new LagPresenter(this);
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_lag;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(_mActivity));
        mRecyclerView.setAdapter(
                mClassificationAdapter = new TabAdapter(R.layout.item_user_classification,
                        null, new OnItemChooseListener<LagInfoBean>() {
                    @Override
                    public void onChoose(LagInfoBean lagInfoBean) {
                        //小修
                        ContentFragment contentFragment = findChildFragment(ContentFragment.class);
                        if (contentFragment != null) {
                            contentFragment.replaceFragment(ContentFragment
                                    .newInstance(lagInfoBean), true);
                        }
                    }
                }));
    }

    @Override
    public void showData(List<LagInfoBean> lagInfoBeans) {
        mClassificationAdapter.setNewData(new DataConvert().convertList(lagInfoBeans));
    }
}